/**
 * Created by Admin on 2018/1/10.
 */
define(function (require, exports, module) {
    var commonPaging = require("../common/commonPagingCq.js");
    var tpl = require("./tpl/obligeeDistributeTpl.html");
    var template = require("template");
    require("../common/dialog.js");
    require("../common/My97DatePicker1/WdatePicker.js");
    require("../common/qy-template");
    require("../seajs-init");

    var p = new commonPaging({
        htmlContainer: "#Js_page_content",
        pageContainer: "#Js_fs_paging",
        url: window.jkconfig.webapiurlv + "analysis/applicantAnalysis",
        tpl: tpl,
        data: $("#searchForm").serialize()
    });

    p.init();

    $(function () {
        $("body").on("click", ".btnConfirm", function () {
            /*判断areaId不为空*/
            if ($("#areaId").val() == "") {
                $.showErr("请选择区域!");
                /*判断patId不为空*/
            } else if ($("[name=checkItem]:checked").length < 1) {
                $.showErr("请选择申请专利");
            } else {
                var areaId = $("#areaId").val();
                var patId = [];
                var checkItems = $("[name=checkItem]:checked");
                $.each(checkItems, function (index, element) {
                    patId.push($(element).attr("data-patId"));
                })
                patId.join("");
                $.ajax({
                    url: window.jkconfig.webapiurlv + "analysis/patentApply/classify?areaId=" + areaId + "&patId=" + patId,
                    success: function (data) {
                        if (data.code == 0) {
                            $.showSuccessTimeout("归类成功!", function () {
                                window.location.reload()
                            })
                        } else {
                            $.showErr("归类失败!")
                        }
                    }
                })
            }
        }).on("click", ".btnSearch", function () {
            searchFn();
        }).on("click", ".ptmt-curpointer", function () {
            if ($(this).children(".up").length > 0) {
                $(this).children(".up").removeClass("up").addClass("down");
                $("[name=order]").val("asc");
                $("[name=sort]").val($(this).attr("data-sort"));
                searchFn();
            } else {
                $(this).children(".down").removeClass("down").addClass("up");
                $("[name=order]").val("desc");
                $("[name=sort]").val($(this).attr("data-sort"));
                $("[name=pageSize]").val(15);
                searchFn();
            }
        }).on("click", ".btnExport", function () {
            $("[name=pageSize]").val(5000);
            window.location.href = window.jkconfig.webapiurlv + "analysisexport/applicantAnalysis?" + $("#searchForm").serialize() + "&" + api_key + "=" + token;
        })

        $('body').on('click', '[data-application-title]', function () {
            var self = $(this);
            window.localStorage.setItem('applyPerson', self.text())
            window.top.location.href = "/index.html#/analysis/patSearch.html";
        })

    })

    function searchFn() {
        $("[name=applicantName]").val($.trim($("[name=applicantName]").val()));
        debugger
        if ($("#Js_fs_paging").css("display") == "block") {
            p.page.destroy && p.page.destroy();
            $("[name=pageNumber]").val(1);
            p = new commonPaging({
                htmlContainer: "#Js_page_content",
                pageContainer: "#Js_fs_paging",
                url: window.jkconfig.webapiurlv + "analysis/applicantAnalysis",
                tpl: tpl,
                data: $("#searchForm").serialize()
            });
            p.init();
        } else {
            p = new commonPaging({
                htmlContainer: "#Js_page_content",
                pageContainer: "#Js_fs_paging",
                url: window.jkconfig.webapiurlv + "analysis/applicantAnalysis",
                tpl: tpl,
                data: $("#searchForm").serialize()
            });
            p.init();
        }
    }
})